<?php

$query = $_GET["query"];

if ($handle = opendir('pages')) {
    echo "{\"query\": \"".$query."\", suggestions: [";
    while (false !== ($file = readdir($handle))) {
        if ($file == "." || $file == "..") continue;
        $file = substr($file, 0, strlen($file)-4);
        if (stristr($file, $query))
            echo "\"".$file."\",";
    }
    echo "]}";
    closedir($handle);
}

?>
